//
//  WeightDetailView.swift
//  Kosspot
//
//  Created by 李鑫 on 2025/7/30.
//

import SwiftUI

struct WeightDetailView: View {
    @State private var selectedDate: Date = Date()
    let data: [WDataItem] = {
            var items = [WDataItem]()
            for hour in 0..<25 {
                let timeString = String(format: "%02d:00", hour)
                let randomScore = Int.random(in: 40...60)
                items.append(WDataItem(timeRange: timeString, weight: Double(randomScore)))
            }
            return items
        }()
    var body: some View {
        VStack {
            CustomNavigationBar(rightImageName: nil, title: "体重") {}
            HStack {
                WeekdayPicker(backGroundColor: Color(hex: "#62D5B6")) { Date in
                    print(Date)
                    selectedDate = Date
                }
                Image("日历 1")
                    .resizable()
                    .frame(width: 20,height: 20)
                    .onTapGesture {
                        
                    }
            }
            .padding(.horizontal,12)
            
            ScrollView(.vertical,showsIndicators: false) {
                VStack(alignment: .leading) {
                    Text("4月8日 21：53")
                        .font(.system(size: 14))
                        .foregroundStyle(Color(hex: "#B2B2B2"))
                        .padding(.leading,16)
                        .padding(.top,16)
                    Spacer().frame(height: 8)
                    HStack(spacing: 4){
                        Text("55.00")
                            .font(.system(size: 24))
                            .foregroundStyle(Color(hex: "#FFFFFF"))
                        Text("KG")
                            .font(.system(size: 14))
                            .foregroundStyle(Color(hex: "#FFFFFF"))
                            Spacer()
                    }
                    .padding(.leading,16)
                    Spacer().frame(height: 12)
                    WeightChartView(data: data)
                        .padding(.horizontal,27)
                        .padding(.bottom,16)
                }
                .background(Color(hex: "#1E1E1E"))
                .cornerRadius(16, corners:[.topLeft,.topRight,.bottomLeft,.bottomRight])
                .padding(.horizontal,12)
                Spacer().frame(height: 12)
                VStack {
                    HStack(spacing: 2) {
                        Text("最新值")
                            .font(.system(size: 16))
                            .foregroundStyle(Color(hex: "#FFFFFF"))
                        Text("(更新时间3月29日16:56)")
                            .font(.system(size: 12))
                            .foregroundStyle(Color(hex: "#F5F5F5"))
                        Spacer()
                        Text("55")
                            .font(.system(size: 16))
                            .foregroundStyle(Color(hex: "#FFFFFF"))
                        Text("公斤")
                            .font(.system(size: 16))
                            .foregroundStyle(Color(hex: "#FFFFFF"))
                    }
                    .padding(.horizontal,20)
                    .padding(.top,20)
                    Spacer().frame(height: 26)
                    SegmentedProgressBar(segments: [
                        (value: 25, color: Color(hex: "#DCFEF7")),
                        (value: 25, color: Color(hex: "#B9FCE8")),
                        (value: 25, color: Color(hex: "#98FCD4")),
                        (value: 25, color: Color(hex: "#62D5B6"))
                    ], currentValue: 55, showWord: ["偏瘦","理想","偏胖","肥胖"])
                        .padding(.horizontal,20)
                        .padding(.bottom,20)
                }
                .background(Color(hex: "#1E1E1E"))
                .cornerRadius(16, corners:[.topLeft,.topRight,.bottomLeft,.bottomRight])
                .padding(.horizontal,12)
                Spacer().frame(height: 12)
                VStack {
                    VStack {
                        HStack {
                            Image("wenhao")
                                .resizable()
                                .frame(width: 16,height: 16)
                            Text("了解BMI指数")
                                .font(.system(size: 16))
                                .foregroundStyle(.white)
                            Spacer()
                        }
                        Spacer().frame(height: 12)
                        Text("BM|指数(Body Mass Index)是身体质量指数，在国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。")
                            .font(.system(size: 14))
                            .foregroundStyle(.white)
                            .lineLimit(10)
                        Spacer().frame(height: 10)
                        Text("计算规则: 指用体重(公斤)除以身高(米)的平方得出的指数。")
                            .font(.system(size: 14))
                            .foregroundStyle(.white)
                            .lineLimit(10)
                    }
                    .padding(.top,20)
                    .padding(.bottom,20)
                    .padding(.horizontal,20)
                }
                .background(Color(hex: "#1E1E1E"))
                .cornerRadius(16, corners:[.topLeft,.topRight,.bottomLeft,.bottomRight])
                .padding(.horizontal,12)
            }
            Spacer()
            
            HStack {
                Button {
                  //更新体重
                    
                    
                } label: {
                    Text("更新体重")
                        .font(.system(size: 16))
                        .foregroundStyle(Color(hex: "#242424"))
                }
            }
            .frame(maxWidth: .infinity, alignment: .center)
            .frame(height: 44)
            .gradientBackground(colors: [Color(hex: "#00F3AF"),Color(hex: "#00E9DA")], type: .linear(start: .leading, end: .trailing), cornerRadius: 22.0)
            .padding(.horizontal,12)
            .padding(.bottom,20)
        }
        .navigationBarHidden(true)
        .background(Color(hex: "#0A0A0A"))
        .edgesIgnoringSafeArea(.all)
    }
}


